package com.trkj.liuyan;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import com.trkj.liuyan.LiuYan;
import com.trkj.liuyan.RowMapper;

public class LiuYanDAO extends BaseDAO{

	public void add(String content, String name, String e_mail){
		
		String sql="insert into liuyan(content,name,e_mail,fdate) values(?,?,?,?)";
		super.executeUpdate(sql, content,name,e_mail,new Date());
		
	}
	
	public void delete(int id){
		
		String sql="delete from liuyan where id=?";
		super.executeUpdate(sql, id);
		
	}
	
	public List<LiuYan>queryAlld(){
		
		String sql = "select id, content, name, e_mail, fdate from liuyan order by fdate desc";
		List<LiuYan> list = super.executeQuery(sql, new RowMapper<LiuYan>(){
			
			@Override
			public LiuYan mapper(ResultSet rs) throws SQLException {
				
				LiuYan liuYan = new LiuYan(
						rs.getInt(1),
						rs.getString(2),
						rs.getString(3),
						rs.getString(4),
						rs.getDate(5));
				return liuYan;
			}
			
		});
		
		return list;
		
	}
	
	public List<LiuYan>queryAlla(){
		
		String sql = "select * from liuyan order by fdate asc";
		List<LiuYan> list = super.executeQuery(sql, new RowMapper<LiuYan>(){
			
			@Override
			public LiuYan mapper(ResultSet rs) throws SQLException {
				
				LiuYan liuYan = new LiuYan(
						rs.getInt(1),
						rs.getString(2),
						rs.getString(3),
						rs.getString(4),
						rs.getDate(5));
				return liuYan;
			}
			
		});
		
		return list;
		
	}
	
}
